<template>
    <rx-dialog @handOk="handleSubmit" @cancel="cancel">
        <rx-layout>
            <div slot="header"  >
                <div class="table-page-search-wrapper" border="false">
                    <a-form layout="inline">
                        <a-row :gutter="24">
                            <a-col  :span="8">
                                <a-form-item :label="$ti18('rxForm.name','名称')">
                                    <a-input :placeholder="$ti18('rxForm.name','名称','','input')" v-model="queryParam.Q_NAME__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col  :span="8">
                                <a-form-item :label="$ti18('rxForm.rxAlias','别名')">
                                    <a-input :placeholder="$ti18('rxForm.rxAlias','别名','','input')" v-model="queryParam.Q_ALIAS__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col  :span="8">
                              <span class="table-page-search-submitButtons">
                                <a-button type="primary" @click="$refs.table.loadData()" icon="search">{{$ti18('rxList.searchBtn','查询')}}</a-button>
                                <a-button style="margin-left: 4px" @click="resetSearch">{{$ti18('rxList.resetBtn','重置')}}</a-button>
                              </span>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
            </div>
            <div slot="center" style>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="false"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formCustom/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                     <span slot="type" slot-scope="{ text, record }">
                        <a-tag :color="typeMap[text].color">
                            <span>{{ typeMap[text].text }}</span>
                        </a-tag>
                    </span>
                    <span slot="name" slot-scope="{ text, record }">
                        {{$i18(record.name,"定制名国际化")}}
                    </span>
                    <span slot="isShare" slot-scope="{ text, record }">
                        {{record.createBy != "SHARE" ? $ti18('rxList.no', '否') : $ti18('rxList.yes', '是')}}
                    </span>
                  <span slot="shareAppName" slot-scope="{text,record}">
                          {{record.createBy == "SHARE"?$i18(record.updateBy,'应用名称'):curApp.appName}}
                        </span>
                </rx-grid>
            </div>
        </rx-layout>
    </rx-dialog>
</template>

<script>

import FormCalendarViewApi from '@/api/form/core/formCalendarView'
import {BaseList, RxFit, RxGrid, Util,JsConstant} from "@lowcode/jpaas-common-lib";

export default {
    name: 'CalendarViewDialog',
    mixins: [BaseList],
    components: {
        RxFit
    },
    props: {
        type:{
          type: String,
          default: ""
        },
        appId:{
            type: String,
            default: "0"
        },
        layerid: {
            type: String,
            default: ""
        },
        destroy: {
            type: Function
        },
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 100,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.$ti18('rxForm.name','名称'), dataIndex: 'name', width: 100,scopedSlots: {customRender: 'name'}},
                {title: this.$ti18('rxForm.rxAlias','别名'), dataIndex: 'alias', width: 100},
                {title: this.$ti18('rxForm.type','类型'), dataIndex: 'type', width: 100, scopedSlots: {customRender: 'type'}},
                {
                    title: this.$ti18('rxList.share','共享'),
                    dataIndex: 'isShare',
                    width:80,
                    scopedSlots: { customRender: 'isShare' }
                },
              {
                title: this.$ti18('rxList.shareAppName', '所属应用'),
                dataIndex: 'shareAppName',
                width: 80,
                scopedSlots: { customRender: 'shareAppName' }
              }
            ],
            typeMap: {
                "custom": {color: 'green', text: this.i18n('customDialog.customLayout','自定义布局')},
                "drag": {color: 'red', text: this.i18n('customDialog.dropLayout','拖拽布局')},
                "free": {color: 'yellow', text: this.i18n('customDialog.freeLayout','自由布局')},
                "": {color: 'red', text: this.i18n('customDialog.none','无')}
            },
        }
    },
    created() {
        if(this.type){
          this.queryParam.Q_TYPE__S_EQ=this.type;
        }
        this.needFilterAppId();
        if (this.appId && this.appId!=0){

            this.queryParam.Q_APP_ID__S_EQ=this.appId;
        }
        //用来判断是否显示共享数据
        this.queryParam.SHARE = true;

    },
    mounted() {
        if(!this.appId){
            //删除共享数据列
            this.$refs.table.initColumns(this.columns.splice(4,1));
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"formBoList",key);
        },
        getListByParams(parameter) {
            return FormCalendarViewApi.query(parameter)
        },
        search() {
            this.$refs.table.loadData()
        },
        handleSubmit(vm) {
            if(this.selectedRows.length==0){
                this.$message.warning(this.i18n('formReport.selectedRows','请选择至少一个'));
                vm.loading=false;
                return;
            }
            Util.closeWindow(this,"ok",this.selectedRows[0])
        },
        cancel() {
            Util.closeWindow(this,"cancel")
        },
        resetSearch() {
            this.queryParam = {};
            if(this.type){
                this.queryParam.Q_TYPE__S_EQ=this.type;
            }
            if(this.appId){
                this.queryParam.Q_APP_ID__S_EQ = this.appId;
                //用来判断是否显示共享数据
                this.queryParam.SHARE = true;
            }
            this.$nextTick(() => {
                this.$refs.table.loadData();
            })
        }
    }
}
</script>
<style scoped>

</style>

